package contracts;

import services.BlocService;
import utils.Tresor;
import utils.Type;
import decorators.BlocDecorator;

public class BlocContract extends BlocDecorator implements BlocService{

	public BlocContract(BlocService delegate){
		super(delegate);
	}
	
	/**
	 * checkInvariant verifie que les invariants sont bien respectes.
	 * pour le service Bloc, il n'y a pas d'invariants...
	 * @throws ContractException
	 */
	public void checkInvariant() throws ContractException {}
	
	public void init(Type type, Tresor tresor) throws ContractException{
		
		super.init(type, tresor);
		
		this.checkInvariant();
		
		//\post getType(init(type,tresor)) = type
		if(!getType().equals(type)){
			throw new PostconditionException("Type de bloc invalide : init");
		}
		
		//\post getTresor(init(type,tresor)) = tresor
		if(!getTresor().equals(tresor)){
			throw new PostconditionException("Tresor invalide : init");
		}
	}
	
}
